package com.tianqu.tms.www.transfer.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.User;
import com.tianqu.tms.www.transfer.viewhelper.TransferWorkCountViewHelper;

public class TransferWorkCountSearchInputAction extends TmsAction {

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		if(uc.getAttribute(TmsConstants.VIEWHELP)!=null)
		{
			uc.removeAttribute(TmsConstants.VIEWHELP);
		}
		TransferWorkCountViewHelper viewhelper = new TransferWorkCountViewHelper();
		
		TmsUserProfile profile = uc.getUserProfile();
		String userName = profile.getLoginId();
		String str = Registry.getConfig(TmsConstants.WWW_WORKCOUNT_PERMISSION_KEY);
		if(!StringUtil.isNullOrBlank(str) && str.indexOf(userName) > -1){
			User user = new User();
			List userList = user.getUserListByRole();
			viewhelper.setUserList(userList);
			viewhelper.setFlag(1);
		}else{
			viewhelper.setUserName(profile.getRealName());
			viewhelper.setUserid(String.valueOf(profile.getUniqueId()));
			viewhelper.setFlag(2);
		}
		uc.setAttribute(TmsConstants.VIEWHELP, viewhelper);
		request.setAttribute(TmsAction.VIEWHELP, viewhelper);
		return mapping.findForward(TmsConstants.SUCCESS); 
		
		
	}

}
